export default {
  data() {
    return {
      formData: {
        username: '',
        password: ''
      },
      userNameRules: [
        { validate: (val) => !!val, message: '必须填写用户名'},
        { validate: (val) => val.length >= 3 && val.length <= 8, message: '用户名长度大于2小于11'},
      ],
      passwordRules: [
        { validate: (val) => !!val, message: '必须填写密码'},
        { validate: (val) => val.length >= 6 && val.length <= 24, message: '密码长度大于5小于24'},
      ]
    }
  },
  methods: {
    fnAjax(url, route) {
      const router = this.$router;
      this.$api.post(url, this.formData)
        .then( data => {
          this.$swal(data.message, '', data.success ? 'success' : 'warning');
          setTimeout(() => this.$swal.close(), 1500);
          if( data.success ) router.push(route || '/')
        })
    },
  }
}